package com.example.scheduleendpoint.config;

import com.example.scheduleendpoint.schedule.ScheduleMethodHandlerAdapter;
import com.example.scheduleendpoint.schedule.ScheduleMethodHandlerMapping;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * 根据配置属性控制是否启用该配置。
 * <br />
 * spring.schedule.endpoint.enabled = true 启用配置 <br />
 * spring.schedule.endpoint.enabled = false 禁用配置 <br />
 */
@ConditionalOnProperty(prefix = "spring.schedule.endpoint", value = "enabled", havingValue = "true", matchIfMissing = false)
@Configuration
public class ScheduleEndpointConfiguration {
    /**
     * 注册 ScheduleMethodHandlerAdapter Bean
     * @return
     */
    @Bean
    public ScheduleMethodHandlerAdapter scheduleMethodHandlerAdapter(){
        return new ScheduleMethodHandlerAdapter();
    }

    /**
     * 注册ScheduleMethodHandlerMapping Bean
     * @return
     */
    @Bean
    public ScheduleMethodHandlerMapping scheduleMethodHandlerMapping(){
        return new ScheduleMethodHandlerMapping();
    }
}
